<!--
  -   合同模板管理.   :permission="permissionList"
  - Author: ys
  -->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :search.sync="searchForm"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-del="handleDelete"
        @search-reset="searchReset"
      >
        <template
          slot="signDateSearch"
        >
          <!-- <el-input
            placeholder="自定义输入框"
            v-model="search.signDate"
          ></el-input> -->
          <!-- <el-date-picker
            v-model="search.signDate"
            type="daterange"
            range-separator="~"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            :picker-options="pickerOptions0"
          >
          </el-date-picker> -->
        </template>

        <template
          slot="templateName"
          slot-scope="scope"
        >
          <el-link
            type="primary"
            :underline="false"
            @click="handleDownFile('downFile',scope.row)"
          >{{scope.row.templateName}}</el-link>
        </template>

        <template
          slot="menuLeft"
          slot-scope="scope"
        >
          <el-button
            class="filter-item"
            type="primary"
            icon="el-icon-plus"
            @click="addOrUpdateHandle('add','')"
          >
            新增
          </el-button>
        </template>
        <template
          slot="menu"
          slot-scope="scope"
        >

          <el-button
            type="text"
            @click="addOrUpdateHandle('edit',scope.row.id)"
          >
            编辑
          </el-button>
          <el-button
            type="text"
            @click="handleDelete(scope.row,scope.index)"
          >
            删除
          </el-button>
        </template>
      </avue-crud>

      <table-form
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getList"
      ></table-form>
     <!-- <table-forms
        v-if="viewVisible"
        ref="viewBtn"
        @refreshDataList="getList"
        @openxuqian="openxuqian"
      ></table-forms> -->
      <!--<table-form v-if="viewVisible" ref="viewBtn" @refreshDataList="getList"></table-form>-->
    </basic-container>
  </div>
</template>

<script>
import {
  fetchList,
  delObj,
} from '@/api/market/contractTemplate/person'
import {
  tableOption
} from '@/const/crud/market/contractTemplate/person'
import TableForm from './CtContractForm'
// import TableForms from './CtContractModifys'
import UpdatePrice from './updatePrice'
import {
  mapGetters
} from 'vuex'
// import request from '@/router/axios'
// import { ExportUrlFile } from '@/api/common'
import TableFormss from '@/views/market/estate/rmproject/RmProjectModify'
export default {
  name: 'contract',
  components: {
    TableForm,
    // TableForms,
    TableFormss,
    UpdatePrice
  },
  data () {
    return {
      viewVisibles: false,
      // pickerOptions0: {
      //   disabledDate (time) {
      //     return time.getTime() > Date.now() - 8.64e6;//如果没有后面的-8.64e6就是不可以选择今天的
      //   }
      // },
      search: {
        signDate: []
      },
      addOrUpdateVisible: false,
      viewVisible: false,
      searchForm: {
      },
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      uploadlg: {
        show: false,
        noUploadFile: true
      },
      tableLoading: true,
      tableOption: tableOption,
      activeName: '0',
    }
  },
  // filters: {
  //   getCtContractProject (val, item, index) {
  //     if (item) {
  //       let arr = item.split(',')
  //       return arr[index]
  //     } else {
  //       return ''
  //     }
  //   }
  // },
  created () {

  },
  computed: {
    ...mapGetters(['elements', 'permissions']),
    ComProjectId (val) {
      debugger
      console.log(val)
      if (val) {
        let arr = val.split(',')
        return arr
      } else {
        return []
      }
    }
  },
  methods: {
    handleViewEstate: function (method, id) {
      // this.viewVisibles = true
      // let arr = ids.split(',')
      // let id = null
      // arr.forEach((item, indexs) => {
      //   if (indexs == index) {
      //     id = item
      //   }
      // })
      this.$refs.viewBtns.init(method, id)
    },
    BeforeClose () {
      this.uploadlg.show = false
      this.$refs.upload.clearFiles()
    },

    refreshList () {
      this.getList(this.page)
    },

    getList (page, params) {

      //this.tableData =  [{ "id": "14", "contractNumber": "Z20190917001","contractTotalAmount":"12333", "companyName": "重庆市旺源汽车销售有限公司", "projectBuildingId": "1", "createDate": "2018-04-20 07:15:18", "updateDate": "2020-07-14 19:04:15", "contractTypeName": "100", "signDate": "2020-07-14", "projectName": "B1-17-19", "contractStatus": "0", "createBy": "Z20190917001", "updateBy": "Z20190917001" }]
      //this.page.total = 1
      this.searchForm.contractStatus = this.activeName
      this.tableLoading = true
      if (this.search.signDate.length > 0) {
        this.searchForm.signStartDate = this.search.signDate[0]
        this.searchForm.signEndDate = this.search.signDate[1]
      } else {
        this.searchForm.signStartDate = ''
        this.searchForm.signEndDate = ''
      }
      fetchList(Object.assign({
        current: this.page.currentPage,
        size: this.page.pageSize
      }, params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 删除
    handleDelete: function (row, index) {
      this.$confirm('是否确认删除此条数据？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(row.id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getList(this.page)
      })
    },
    // 查看
    handleView: function (method, row) {
      this.viewVisible = true
      this.$nextTick(() => {
        this.$refs.viewBtn.init(method, row.id, row.ctContractProject)
      })
    },
    //下载文件
    handleDownFile: function (method, row) {
      console.log(row)
    },
    // 新增、修改
    addOrUpdateHandle (method, id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(method, id)
      })
    },


    sizeChange (pageSize) {
      this.page.pageSize = pageSize
    },
    currentChange (current) {
      this.page.currentPage = current
    },
    searchChange (form, done) {
      // this.searchForm = form
      this.page.currentPage = 1
      this.getList(this.page, form)
      done()
    },
    searchReset () {
      this.search.signDate = []
    },
    refreshChange () {
      this.getList(this.page)
    },
  }
}
</script>
<style lang="scss" scoped>
</style>
